<!DOCTYPE html>
<html>
<head>
    <title>修改住院信息--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>
 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }
        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
    <script type="text/javascript">
    var blh = getQueryVariable("blh");
    var ghks = decodeURI(getQueryVariable("ghks"));
    // alert(ghks);
    var zzys = getQueryVariable("zzys");
    var pageNum = getQueryVariable("pageNum");

    //页面初始化
    $(function () {
        $('#backid').click(function(){
            window.location.href="/hospital/index.html?pageNum="+pageNum;
        });
        $("#blh").html(blh);
        //使Ajax同步执行而不是默认的异步执行
        $.ajax({
            //
            url:"/zhuyuandetail/"+blh,
            data:"",
            type: "GET",
            success:function (vo) {
                console.log(vo);
                let obj = vo.obj;
                $("input[name=blh]").val(blh);
                $("#xm").html(obj.xm);
                $("#zjlx").html(obj.zjlx);
                $("#zjh").html(obj.zjh);
                $("#sbh").html(obj.sbh);
                $("#phone").html(obj.phone);
                let sfzfs = $("input[name=sfzf]");
                for (let i = 0; i < sfzfs.length; i++) {
                    // alert($(sfzfs[i]).val() + ", " + obj.sfzf)
                    if (sfzfs[i].value == obj.sfzf) sfzfs[i].checked = true;
                }

                let genders = $("input[name=gender]");
                for (let i = 0; i < genders.length; i++) {
                    // alert($(sfzfs[i]).val() + ", " + obj.sfzf)
                    if (genders[i].value == obj.gender) genders[i].checked = true;
                }

                $("input[name=age]").val(obj.age);
                // $("input[name=job]").val(obj.job);

                let cfzs = $("input[name=cfz]");
                for (let i = 0; i < cfzs.length; i++) {
                    // alert($(sfzfs[i]).val() + ", " + obj.sfzf)
                    if (cfzs[i].value == obj.cfz) cfzs[i].checked = true;
                }

                loadKeshi();
                loadDoc();

                $("#bz").html(obj.bz);
                $("input[name=hlr]").val(obj.hlr);
                $("input[name=cwh]").val(obj.cwh);
                $("#bq").html(obj.bq);
            }
        })
        //异步请求，后端更新数据
        $("#saveInfo").click(function (){
            // alert($("#modifiedForm").serialize());
            // alert($("#modifiedForm").serialize() + "&_method = PUT");
            $.ajax({
                url:"/updateZyxx",
                type:"POST",
                data:$("#modifiedForm").serialize() + "&bz=" + $("#bz").val() +"&bq=" + $("#bq").val() + "&_method=PUT",
                dataType:"JSON",
                success:function (vo) {
                    if (vo.code == 200){
                        alert(vo.message);
                        // alert("pageNum:"+$("#currentPageInput").val());
                        window.location.href = "/hospital/index.html?pageNum=" + pageNum;
                    } else{
                        alert(vo.message);
                    }
                }
            })
        });
    });
    //加载科室数据
    function loadKeshi(){
        $.ajax({
            url:"/keshilist",
            type: 'GET',
            data:"",
            dataType:'JSON',
            async:false,
            success:function (vo){
                let keshis = vo.objList;
                let options = "";
                for (let i = 0; i < keshis.length; i++) {
                    let ks = keshis[i];
                    let selected = ghks == ks.ksmc?"selected=\'selected\'":"";
                    options += "<option value=" + "\'" + ks.id + "\'" + selected + ">" + ks.ksmc + "</option>"
                }
                // console.log(vo);
                $("#ksSelect").html(options);
            }
        })
    }
    //加载医生数据
    function loadDoc() {
        $.ajax({
            url:"/doclist",
            type: 'GET',
            data:"",
            dataType:'JSON',
            async:false,
            success:function (vo){
                let docs = vo.objList;
                let options = "";
                for (let i = 0; i < docs.length; i++) {
                    let doc = docs[i];
                    let selected = zzys == doc.xm?"selected=\'selected\'":"";
                    options += "<option value=" + "\'" + doc.docid + "\'" + selected + ">" + doc.xm + "</option>"
                }
                console.log(vo);
                $("#docSelect").html(options);
            }
        })
    }
    //从url里获取参数，window.location.search.search从问号(?)开始的 URL（查询部分）
    function getQueryVariable(variable){
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return false;
    }
    </script>
</head>
<body>
<form id="modifiedForm" class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td width="10%" class="tableleft">病历号</td>
        <td id="blh"></td>
        <input type="text" name="blh" value="" style="display: none"/>
    </tr>
    <tr>
        <td width="10%" class="tableleft">姓名</td>
        <td id="xm"></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">证件类型</td>
        <td id="zjlx"></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">证件号</td>
        <td id="zjh"></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">社保号</td>
        <td id="sbh"></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">联系电话</td>
        <td id="phone"></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">是否自费</td>
        <td><input type="radio" name="sfzf" value="0" checked/>否&nbsp;&nbsp;&nbsp;
            <input type="radio" name="sfzf" value="1"/>是
        </td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">性别</td>
        <td><input type="radio" name="gender" value="1" checked/>男&nbsp;&nbsp;&nbsp;
            <input type="radio" name="gender" value="0"/>女</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">年龄</td>
        <td><input type="text" name="age"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">初复诊</td>
        <td><input type="radio" name="cfz" value="0" checked/>初诊&nbsp;&nbsp;&nbsp;
            <input type="radio" name="cfz" value="1"/>复诊</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">所挂科室</td>
        <td><select id="ksSelect"></select></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">指定医生</td>
        <td><select id="docSelect" name="docid"></select></td>
    </tr>
	<tr>
        <td width="10%" class="tableleft">备注</td>
        <td><textarea id="bz"></textarea></td>
	</tr>
    <tr>
        <td width="10%" class="tableleft">护理</td>
        <td><input type="text" name="hlr" value=""/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">床位号</td>
        <td><input type="text" name="cwh" value=""/></td>
    </tr>

    <tr>
        <td width="10%" class="tableleft">病情</td>
        <td><textarea id="bq"></textarea></td>
    </tr>
    <tr>
        <td colspan="2">
			<center>
				<button class="btn btn-primary" type="button" id="saveInfo">保存</button> &nbsp;&nbsp;
                <button class="btn btn-success" type="button" name="backid" id="backid">返回列表</button>
			</center>
		</td>
    </tr>
</table>
</form>
</body>
</html>